package network

import (
	"fmt"
	"net"
	"strings"

	"gitee.com/liumou_site/gcs"
)

// AddConnect 方法用于通过 nmcli 工具添加一个新的网络连接。
func (c *NmcliConnectionStruct) AddConnect() error {
	c.Address = net.ParseIP("127.0.0.1")
	c.Dns = strings.Split("114.114.114.114 8.8.8.8", " ")
	c.Gw = net.ParseIP("10.1.1.1")
	c.Mask = 24
	c.uuid = "as216a5w4d1646"
	c.Method = "auto"
	c.Types = "ethernet"
	c.Name = "test"
	c.Dev = "eth0"
	cmd := fmt.Sprintf("nmcli connection add type %s  con-Name %s ifname %s", c.Types, c.Name, c.Dev)
	fmt.Println(cmd)
	command := gcs.NewShell()
	command.RunShell(cmd)
	return command.Err
}
